package com.example.testspringes.json;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;

import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Description: //TODO
 * @ProjectName: testspringes
 * @Package: com.example.testspringes.json
 * @Author: FX
 * @CreateDate: 2019/3/29 11:00
 * @Version: 1.0
 * Copyright: Copyright (c) 2019
 */
public class DateJosn extends JsonSerializer<Long> {
    @Override
    public void serialize(Long aLong, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        String format = DateFormatUtils.format(aLong, "yyyy-MM-dd HH:mm:ss");

        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
        Date date = new Date(aLong);
        String format1 = simpleDateFormat.format(date);
        jsonGenerator.writeString(format1);
    }
}
